package org.unicat.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.unicat.mapper.UserInfoMapper;
import org.unicat.mapper.UserMapper;
import org.unicat.model.User;
import org.unicat.model.UserInfo;
import org.unicat.service.UserService;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Autowired
    UserInfoMapper userInfoMapper;

    @Override
    public List<User> findAll() {
        return userMapper.selectAll();
    }

    @Override
    public User findByName(String username) {
        return userMapper.selectOne(username);
    }

    @Override
    public void updateUser(UserInfo userInfo) {
        User user = new User();
        user.setUsername(userInfo.getUsername());
        user.setPassword(userInfo.getPassword());
        userMapper.updateUser(user);
    }

    @Override
    public void updateUserInfo(UserInfo userInfo) {
        userInfoMapper.updateUserInfo(userInfo);
    }

    @Override
    public void deleteUser(UserInfo userInfo) {
        User user = new User();
        user.setUsername(userInfo.getUsername());
        user.setPassword(userInfo.getPassword());
        userMapper.deleteUser(user);
    }

    @Override
    public void deleteUserInfo(UserInfo userInfo) {
        userInfoMapper.deleteUserInfo(userInfo);
    }


}
